package day9;

import java.io.*;
import java.net.Socket;
import java.util.*;

public class LoginThread extends Thread{
    private final Socket s;

    private static Map<String,String> users=new HashMap<>();
    static{
        users.put("wangkaixuan","249+1");
        users.put("zizucheng","251-1");
        users.put("ahao","666");
        users.put("yangshuo","1234567");
        users.put("xueqinghua","pwd");
    }
    public LoginThread(Socket s){
        this.s=s;
    }

    @Override
    public void run() {
        System.out.println("socket连接建立了。。。" + s);
        try {
            InputStream in = s.getInputStream();
            OutputStream out = s.getOutputStream();
            //客户端回，服务器答，
            //BufferedWriter pw=new BufferedWriter(out,true);
            BufferedReader br = new BufferedReader(new InputStreamReader(in));
            PrintWriter pw = new PrintWriter(out, true);
            String name=br.readLine();
            String pass=br.readLine();
            if(pass.equals(users.get(name))){
                pw.println("登录成功");
            }else{
                pw.println("登录失败！");
            }
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            try {
                s.close();
                System.out.println(s+"关闭了。。。聊天结束");
            } catch (Exception e) {
                //e.printStackTrace();
            }
        }
    }
}
